// var http = require('http');
// http.createServer(function(request, response) {
//     response.writeHead(200, { 'Content-Type': 'text/plain' });
//     response.end('Hello World');
// }).listen(8888);
// console.log('Server running at http://127.0.0.1:8888/');

// 创建基本的web服务器
const http = require('http')
const server = http.createServer()
    // 为服务器实例绑定request事件，监听客户端的请求
server.on('request', function(req, res) {
    const url = req.url
    const method = req.method
    const str = `Your request url is ${url},and request method is ${method}`
    console.log(str);
    // 设置Content-Type 响应头，解决中文乱码问题
    res.setHeader('Content-Type', 'text/html;charset=utf-8')

    // 向客户端响应内容
    res.end(str)
})
server.listen(8080, function() {
    console.log('server running at http://127.0.0.1:8080');
})